<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class User_model extends CI_Model{
	function __construct() {
		parent::__construct();
	}
	
	function check_login($usr,$pwd){
		$clause = array(
			'username'=>$usr,
			'user_password'=>md5($pwd)
		);
                $this->db->select('*,TbMDKota.Nama AS nama_kota, TbUser.nama AS nama,TbUser.user_id AS user_id');
                $this->db->join('TblKotaUser','TblKotaUser.user_id=TbUser.user_id','left');
                $this->db->join('TbMDKota','Kode=TblKotaUser.kode_kota','left');
		$query_login = $this->db->get_where('TbUser',$clause);
		if($query_login->num_rows()==1){
			$data_result = $query_login->row_array();
			// user level yang boleh login cuman yg levelnya 0,4,dan 5
			if(($data_result['user_level']==0||$data_result['user_level']==4||$data_result['user_level']==5)&&$data_result['user_active']==1){
                            if($data_result['nama_kota']=='' && $data_result['user_level']==4)
                            {
                                $this->session->set_flashdata('error', '2');
                                return FALSE;
                            }
                            return $data_result;
			}else{
                                $this->session->set_flashdata('error', '1');
				return FALSE;
			}
		}else{
                        $this->session->set_flashdata('error', '1');
			return FALSE;
		}
	}
	
	function get_name($id){
		$query = $this->db->get_where('TbUser',array('user_id'=>$id));
		if($query->num_rows()==1){
			return $query->row()->nama;
		}else{
			return FALSE;
		}
	}
	
}

/** End of file */